//
//  UILable+Additions.swift
//  YMToolKit
//
//  Created by YDWY on 2017/4/20.
//  Copyright © 2017年 YDWY. All rights reserved.
//

import Foundation
import UIKit

extension UILabel {

    
    
    /// 创建UILabel
    ///
    /// - Parameters:
    ///   - text: 文字内容
    ///   - fontSize: 字体大小
    ///   - color: 字体颜色
    /// - Returns: 返回
    class func ym_lable(text: String, fontSize: CGFloat ,color: UIColor ) -> UILabel{
        
        let lab  = UILabel()
        lab.text = text
        lab.font = UIFont.systemFont(ofSize: fontSize)
        lab.textColor = color
        lab.sizeToFit()

        return lab
    }
    
    
    ///label高度自适应
    ///
    /// - Parameters:
    ///   - text: 文字
    ///   - labelWidth: 最大宽度
    ///   - attributes: 字体，行距等
    /// - Returns: 高度
    static func ym_autoHeightWithStr(text:String, labelWidth: CGFloat,attributes:[String:Any]) -> CGFloat {
        
        var size = CGRect()
        let size2 = CGSize(width: labelWidth, height: 0)//设置label 的最大宽度
        size = (text as NSString).boundingRect(with: size2, options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: attributes, context: nil)

        return size.size.height
        
    }
    
    
}
